﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using evt;
using Shop;
using System.Runtime.InteropServices;

public class ZJHShop : MonoBehaviour {

	// Use this for initialization
	private GameObject prefabs = null;
	private int rotationX = -626; 
	private int rotationY = -55;
	public static ResShopItemsMsg msg = null;
	void Start () {
		ServerEventDispather.getInstance ().AddEventDispather (ServerEvent.OPEN_RECHARGE_VIEW, Show);
		EventTriggerListener.Get (gameObject).onClick = Hide;
		prefabs = transform.FindChild ("ShopCell").gameObject;
		Init ();
	}

	private void Init (){
		if( msg == null ){
			return;
		}
		List<ItemInfo> list = msg.items;
		for( int i = 0 ; i < list.Count ; i++ ){
			
			GameObject go = (GameObject)Instantiate (prefabs, transform);
			go.GetComponent<ShopCell> ().Id = list[i].id.ToString();
			go.GetComponent<ShopCell> ().Money = list[i].price.ToString();
			go.GetComponent<ShopCell> ().DiaMonds = list[i].diamond.ToString();

			go.transform.localPosition = new Vector3 (rotationX + i * 310, rotationY, 0);
		}

	}

	public void Hide(GameObject go){
		transform.localPosition = new Vector3(10000,0,0);
	}

	public void Show(object evt){
		transform.localPosition = new Vector3(0,0,0);
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
